package com.waghost.bridalgown.entity;

import lombok.Data;

@Data
public class Result <T>{
    private T data;
    private String message;
    private int code;

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<T>();
        result.setData(data);
        result.setCode(200);
        return result;
    }

    public static <T> Result<T> success(T data, String message){
        Result<T> result = new Result<T>();
        result.setData(data);
        result.setMessage(message);
        result.setCode(200);
        return result;
    }

    public static <T> Result<T> success(T data, String message, int code){
        Result<T> result = new Result<T>();
        result.setData(data);
        result.setMessage(message);
        result.setCode(code);
        return result;
    }

    public static <T> Result<T> error(String message){
        Result<T> result = new Result<T>();
        result.setCode(500);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> noLogin(){
        Result<T> result = new Result<T>();
        result.setCode(401);
        result.setMessage("登录过期");
        return result;
    }

    public static <T> Result<T> toAjax(int code,String successMessage,String errorMessage){
        Result<T> result = new Result<T>();
        result.setCode(code == 1?200:500);
        result.setMessage(code == 1?successMessage:errorMessage);
        return result;
    }
}
